function search_gd(){
			var index = layer.load(1, {shade: [0.1, '#fff'] });
			$.ajax({
				url: APP.api_url + "Sy/get_goods",
				data: {
					agent_id: getValue("agent_id"),
					chain_id:getValue('chain_id'),
					app_id	:APP.app_id,
					name 	:$("#keyword").val(),
					time:Date.parse( new Date())
				},
				success: function(data) {
					layer.close(index);
					var goods=data.goods;
					if(goods){
						$(".sy_prolist").html(set_goods(goods));
						goods_click();
					}
				}
			})	
}

if(!getValue("agent_id")){
		location.href='login.html';
}
function reset_key(){
	document.onkeydown = function(e) {
 	//捕捉回车事件
	 var ev = (typeof event!= 'undefined') ? window.event : e;
	 if(ev.keyCode == 13) {
	  get_goods();
	 	}
	}
}
function topay_common(data,price,type){
		var agent = data.agent;
		if(agent.is_score == 1) {
			price_html = '<p>零售价:¥<em>' + price + '</em>送<em>' + data.zs + '</em></p>' +
			'<p>会员价:¥<em>' + price + '</em>抵<em>' + data.dk + '</em></p>';
		} else {
			price_html = "<p>收款:¥<em>" + price + "</em></p>";
		}
		var html = '<div class="sy_tck">' +
			'<div class="sy_ewmbox">' +
			'<input  type="hidden" id="oid" value="' + data.order_id + '"> ' +
			'<div><input  type="text" name="mem_no" id="mem_no" class="sy_sptsrk" style="width: 75%;border-top-left-radius: 10px;border-bottom-left-radius: 10px;" placeholder="请输入或扫描会员码"></div>' +
			'</br>' +
			'<div><input  type="text" name="mem_card" id="mem_card" class="sy_sptsrk" style="width: 75%;border-top-left-radius: 10px;border-bottom-left-radius: 10px;" placeholder="请输入或扫描会员付款码"></div>' +
			'</br>' +
			'<div><img style="width:150px;height:150px;" src="'+data.url+'"/></div>'+
			'</br>' +
			'<div class="sy_tctip">' + price_html +
			'</div>' +
			'</div>' +
			'<div class="sy_tcbtnbox">' +
			'<a href="#" class="dayin" onclick="print_order(' + data.order_id + ')">打印</a>' +
			'<a href="#" onclick="wanchen('+type+')" class="wanc">完成</a>' +
			'</div>' +
			'</div>';
			layer.open({
				title: '收款码',
				shadeClose: false,
				closeBtn:0,
				shade: 0.8,
				btn: false,
				area: ['650px', '580px'],
				content: html
			});
}
function jz_common(data,price,type){
			var html = '<div class="sy_tck">' +
						'<div class="sy_ewmbox">' +
						'<div class="sy_cgnr">' +
						'<div class="iconfont icon-chenggong"></div>' +
						'</br><p>' + data.msg + '</p>' +
						'</div>' +
						'<div class="sy_tctip">' +
						'<p>¥<em>' + price + '</em></p>' +
						'</div>' +
						'</div>' +
						'<div class="sy_tcbtnbox">' +
						'<a href="#" class="dayin" onclick="print_order(' + data.order_id + ')">打印</a>' +
						'<a href="#" onclick="wanchen('+type+')" class="wanc">完成</a>' +
						'</div>' +
						'</div>';

					layer.open({
						title: '记帐收银',
						shadeClose: false,
						shade: 0.8,
						btn: false,
						area: ['380px', '450px'],
						content: html
					});
}

$("#app_name").text("");
$("#app_mobile").text(APP.app_mobile);
function show_info(pay_price,score){
	var info="赠送0";
	if(score<0){
		info="赠送"+score;
	}
	if(score>0){
		info="抵扣"+score;
	}
		var html='</br><div class="sy_fukbt">'+
			'<span class="iconfont icon-chenggong"></span>'+
			'<span>收款<em>¥'+pay_price+'</em>元,鼓励金'+info+'</span>'+
		'</div>';
	layer.open({
		title: '收款通知',
		shadeClose: false,
		shade: 0.8,
		btn:false,
		area: ['380px', '300px'],
		content: html
	});
}
function set_keyup(type) {
	$("#mem_no").focus();
	document.onkeydown = function(e) {
		//捕捉回车事件
		var ev = (typeof event != 'undefined') ? window.event : e;
		if(ev.keyCode == 13) {
			if(e.srcElement.id == "mem_no") {
				$("#mem_card").focus();
			}
			if(e.srcElement.id == "mem_card") {
				var mem_card = $("#mem_card").val().trim();
				if(mem_card == "") {
					alert("请扫描会员付款码");
					$("#mem_card").focus();
				} else {
					$.ajax({
						url: APP.api_url + "Sy/zhu_pay",
						data: {
							oid: $("#oid").val(),
							mem_no: $("#mem_no").val(),
							mem_card: $("#mem_card").val()
						},
						success: function(data) {
							if(data.code != 200) {
								alert(data.msg);
							} else {
								wanchen(type);
								show_info(data['pay_price'], data['agent_score']);
							}
						}
					})

				}
			}
		}
	}
}

function getValue(name) {
	var member = JSON.parse(localStorage.getItem('member'));
	if(member){
		return member[name];
	}
	return "";
}
function keyup(obj) {
	obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
	obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
	obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
	obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
}
function exit() {
		var con = layer.confirm('确认退出系统?', function(index) {
			localStorage.clear();
			layer.close(con);
			window.location = "login.html";
		});
}
function set_info(){
		$("#sname").text(getValue("chain_name"));
		$("#user").text(getValue("name"));
		$("#toux").attr("src",getValue("logo")?getValue("logo"):'img/member.jpg');
		
}
function print_order(order_id){
		$.ajax({
			url: APP.api_url + "Sy/prt",
			data: {
				order_id: order_id
			},
			success: function(data) {
				
				
			}
		})
	
}
function print_order2(log_id){
		$.ajax({
			url: APP.api_url + "Sy/prt2",
			data: {
				log_id: log_id
			},
			success: function(data) {
								
			}
		})	
}
function print_item(order_id){
		$.ajax({
			url: APP.api_url + "Sy/prt_item",
			data: {
				order_id: order_id
			},
			success: function(data) {
								
			}
		})	
}
function wanchen(type){
	layer.closeAll();
	if(type==1){
		$("#price").val('');
	}else if(type==2){
		cart={};
		$("#list").html('');
		$("#total").text(0);
		reset_key();
	}else if(type==3){
		clear_cart();
	}else if(type==4){
		pay_ok();
	}
}
function clear_cart(){
	$('.sy_proxlist').html('');
	$('#nums').text(0);
	$("#totals").text(0.00);
	cart={};
}
